<?php

namespace Seguridad\Controller\Service;

use Zend\Db\Adapter\Adapter;
use Componentes\Controller\UtilsArrayController;
use Seguridad\Model\Entity\Menu;
use Seguridad\Controller\Service\GenericService;
use Seguridad\Model\Dao\MenuDAO;

//SERVICIO
class MenuService extends GenericService {

    /**
     * @var Zend\Db\Adapter\Adapter 
     */
    private $dbAdapter;
    private static $menuService;

    /**
     * @param \Zend\Db\Adapter\Adapter $dbAdapter
     */
    private function __construct(Adapter $dbAdapter) {
        $this->dbAdapter = $dbAdapter;
    }

    public static function getInstance($adapter) {
        if (self::$menuService == null) {
            self::$menuService = new MenuService($adapter);
        }
        return self::$menuService;
    }

    public function getMenuDao() {
        return MenuDAO::getInstance($this->dbAdapter);
    }

    /**
     * @param type $id
     * @return type
     */
    public function getRegistro($id) {
        $data = null;
        $success = false;
        $menu = $this->obtenerMenuSegunId($id);
        if ($menu->getId() != null) {
            $data[0] = $menu->objectToArray();
            $success = true;
        }
        return UtilsArrayController::organizarOutput($success, $data, null);
    }

//------Retornan los objetos-------

    public function obtenerMenuSegunId($id) {
        $registros = $this->getMenuDao()->getRegistro($id);
        $data = UtilsArrayController::llenarData($registros);
        $menu = new Menu($data[0]);
        return $menu;
    }

}
